﻿/*----------------------------------------------------------------
// Copyright (C) 2011 周士祎
// 版权所有。 
//
// 文件名：RolesInfo
// 文件功能描述：角色管理业务层
//
// 
// 创建标识：2012-01-03 周士祎
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class RolesInfo
    {
        /// <summary>
        /// 角色ID
        /// </summary>
        public string RoleId
        {
            get;
            set;
        }
        /// <summary>
        /// 角色名称
        /// </summary>
        public string RoleName
        {
            get; 
            set;
        }
        /// <summary>
        /// 角色说明
        /// </summary>
        public string RoleMeno
        {
            get;
            set;
        }
        private DataAccessRoles dar;             
        private int rolescount;
        public int _RolesCount
        {
            get { return rolescount; }
        }
        public RolesInfo(bool isgetcount)
        {
            dar = new DataAccessRoles();
            if (isgetcount)
            {
                rolescount = GetRolesCount();
            }
        }
        public RolesInfo()
        { }
        /// <summary>
        /// 获取角色数量
        /// </summary>
        /// <returns></returns>
        private int GetRolesCount()
        {
            return dar.GetRolesCount();
        }
        /// <summary>
        /// 获取角色（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<RolesInfo> GetAllRoles(int pagesize,int startindex)
        {
            IList<RolesInfo> rolelist = new List<RolesInfo>();
            RolesInfo roleinfo;
            DataSet ds = dar.GetAllRoles(pagesize,startindex);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                roleinfo = new RolesInfo()
                {
                    RoleId = item[0].ToString(),
                    RoleName = item[1].ToString(),
                    RoleMeno = item[2].ToString()
                };
                rolelist.Add(roleinfo);                
            }
            return rolelist;
        }
        public IList<RolesInfo> GetAllRoles()
        {
            IList<RolesInfo> rolelist = new List<RolesInfo>();
            RolesInfo roleinfo;
            DataSet ds = dar.GetAllRoles();
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                roleinfo = new RolesInfo()
                {
                    RoleId = item[0].ToString(),
                    RoleName = item[1].ToString(),
                    RoleMeno = item[2].ToString()
                };
                rolelist.Add(roleinfo);
            }
            return rolelist;
        }
        /// <summary>
        /// 保存角色
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveRole(RolesInfo role)
        {
            object[] rolepara = new object[] { role.RoleId, role.RoleName, role.RoleMeno};
            return dar.SaveRole(rolepara);
        }

        public int DeleteRole(string roleid)
        {
            return dar.DeleteRole(roleid);
        }

        public int RoleBindLog(string roleid, string logid)
        {
            return dar.RoleBindLog(roleid, logid);
        }

        public int NotRoleBindLog(string roleid, string logid)
        {
            return dar.NotRoleBindLog(roleid, logid);
        }
    }
}
